const merge = require('webpack-merge');
const webpack = require('webpack');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const commonConfig = require('./webpack.common');
const HtmlWebpackPlugin = require('html-webpack-plugin');

const prodConfig = {
    mode: 'production',
    entry: {
        cms_admin: [
            './src/index.js'
        ]
    },
    module:{
        rules: [
            {
                test: /\.(css|less)$/,
                use: [
                    MiniCssExtractPlugin.loader, // css外链不能局部热更新了, 跟react-hot-loader不兼容
                    'css-loader',
                    'less-loader'
                ]
            }
        ]
    },
    plugins: [
        new MiniCssExtractPlugin({ //开发环境不使用mini-css-extract-plugin 不同的环境配置不同的loader
            filename: '[name].[contenthash].css'
        }),
        new HtmlWebpackPlugin({
            template: './src/template/index.html',
        }),
    ]
}

module.exports = merge(prodConfig, commonConfig);